package com.holike.crm.fragment.message;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.holike.crm.R;
import com.holike.crm.activity.message.MessageDetailsActivity;
import com.holike.crm.bean.MessageResultBean;
import com.holike.crm.bean.MultiItem;

import java.util.List;

/**
 * Created by pony on 2019/12/16.
 * Version v3.0 app报表
 * 百宝箱
 */
public class TreasureChestFragment extends AbsMessageFragment {
    @Override
    String getType() {
        return "4";
    }

    @NonNull
    @Override
    AbsMessageAdapter newAdapter(List<MultiItem> dataList) {
        return new TreasureChestAdapter(mContext, dataList);
    }

    @Override
    public void onNoResult() {
        noData(R.drawable.no_result, R.string.tips_notreasurechest, false);
    }

    @Override
    void onItemClick(MessageResultBean.MessageBean bean, int position) {
        MessageDetailsActivity.open(this, bean.messageId, bean.typeData, REQUEST_CODE);
    }

    private final class TreasureChestAdapter extends AbsMessageAdapter {

        TreasureChestAdapter(Context context, List<MultiItem> dataList) {
            super(context, dataList);
        }

        @Override
        int getItemLayoutResourceId() {
            return R.layout.item_message_general;
        }

        @Override
        void bindHolder(RecyclerHolder holder, MessageResultBean.MessageBean bean, int position) {
            boolean isRead = bean.isRead();
            holder.setVisibility(R.id.iv_isRead, isRead ? View.INVISIBLE : View.VISIBLE);
            int textColor = isRead ? R.color.textColor8 : R.color.textColor4;
            holder.setTextColorRes(R.id.tv_title, textColor);
            holder.setTypeface(R.id.tv_title, isRead ? Typeface.defaultFromStyle(Typeface.NORMAL) : Typeface.defaultFromStyle(Typeface.BOLD));
            holder.setTextColorRes(R.id.tv_type, textColor);
            holder.setBackgroundResource(R.id.tv_type, isRead ? R.drawable.bg_corners4dp_textcolor8 : R.drawable.bg_corners4dp_textcolor4);
            holder.setTextColorRes(R.id.tv_date, textColor);
            holder.setTextColorRes(R.id.tv_time, textColor);
            holder.setTextColorRes(R.id.tv_publisher, textColor);
            holder.setText(R.id.tv_title, bean.title);
            holder.setText(R.id.tv_type, bean.tab);
            holder.setText(R.id.tv_date, bean.date);
            holder.setText(R.id.tv_time, bean.time);
            String publisher = mContext.getString(R.string.message_publisher);
            if (!TextUtils.isEmpty(bean.describe)) {
                publisher += bean.describe;
            }
            holder.setText(R.id.tv_publisher, publisher);
        }
    }
}
